<?php
class Delivery_Model_Horario
	extends Delivery_Model_Abstract
{
	
	public $idHorario;
	public $idNegocio;
	public $dia;	
	public $desde;	
	public $hasta;	

	public function getId()
	{
		return $this->idHorario;	
	}
	
	public function getNextDate()
	{
	
		$now = Zend_Date::now();
		
		$new = clone ($this);
		
		$desde = $new->desde();
		$hasta = $new->hasta();
		
		$compareDate = $now->compareDate( $desde );
		
		if( $compareDate > 0 || ( $compareDate == 0 && $now->compare( $hasta, Zend_Date::TIME_MEDIUM ) > 0)){	

			$desde->addWeek(1);
			$hasta->addWeek(1);
		}
		
		return array($desde->toString(Zend_Date::YEAR . '' .Zend_Date::MONTH . '' . Zend_Date::DAY), $desde, $hasta);
	}
	
	public function __toString()
	{
		return $this->toString();
	}
	
	public function toString()
	{
		$desde = new Zend_Date(  );
		$desde->set( $this->dia-1, Zend_Date::WEEKDAY_DIGIT);
		$desde->set( $this->desde, Zend_Date::TIME_MEDIUM);
		
		$hasta = clone $desde;
		$hasta->set( $this->hasta, Zend_Date::TIME_MEDIUM);
		
		return	ucfirst($desde->toString(Zend_Date::WEEKDAY)) . ": "
				. $desde->toString(Zend_Date::TIME_SHORT). " - "
				. $hasta->toString(Zend_Date::TIME_SHORT);
	}
	
	public function getDayName()
	{
//		$desde = new Zend_Date(  );
//		$desde->set( $this->dia-1, Zend_Date::WEEKDAY_DIGIT);
//		$desde->set( $this->desde, Zend_Date::TIME_MEDIUM);
		
	    $desde = $this->desde();
	    
		return	ucfirst($desde->toString(Zend_Date::WEEKDAY));
	}
	
	public function isToday()
	{
		$desde = new Zend_Date(  );
		$desde->set( $this->dia-1, Zend_Date::WEEKDAY_DIGIT);
		$desde->set( $this->desde, Zend_Date::TIME_MEDIUM);
		
		$now = Zend_Date::now();
		
		return	$now->compareDate( $desde ) == 0;
	}
	
	public function desde()
	{
		$desde = new Zend_Date(  );
		$desde->set( $this->dia-1, Zend_Date::WEEKDAY_DIGIT);
		$desde->set( $this->desde, Zend_Date::TIME_MEDIUM);
		
		return $desde;
	}
	
	public function hasta()
	{
		$hasta = new Zend_Date(  );
		$hasta->set( $this->dia-1, Zend_Date::WEEKDAY_DIGIT);
		$hasta->set( $this->hasta, Zend_Date::TIME_MEDIUM);
		
		return $hasta;
	}
	
}